package com.vito.email;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.vito.base.util.FreeMarkerUtil;
import com.vito.base.util.Pty;
import com.vito.base.util.StringUtil;

public class MailSenderInfoExt extends MailSenderInfo {
	// 邮件发送者昵称
	private String fromNick = Pty.get("conf/email/email").getProp("fromNick");
	// 邮件的文本内容
	private String content;

	public String setFtlExt(String ftl) throws IOException {
		if (StringUtils.isNotBlank(ftl)) {
			FreeMarkerUtil fm = new FreeMarkerUtil(
					SendMailUtil.class.getClassLoader().getResource("/").getPath() + "conf/email/");
			File file = new File(StringUtil.getUUID());
			try {
				FileWriter writer = new FileWriter(file);
				fm.createFile(ftl, data, writer);
				this.content = fm.getContent(file, "<body>", "</body>");
			} finally {
				if (file != null && file.exists())
					file.delete();
			}
		}
		return this.content;
	}

	private Map<String, Object> data = new HashMap<String, Object>();

	public void put(String key, Object value) {
		data.put(key, value);
	}

	public String getFromNick() {
		return fromNick;
	}

	public void setFromNick(String fromNick) {
		this.fromNick = fromNick;
	}

	public String getContent() {
		return content;
	}

	public String setContent(String content) {
		return this.content = content;
	}

}
